package tests;

import java.util.LinkedList;

import retrievedatafromrevishapi.GetReviewDataFromApi;

import bookworm.Review;

public class GetReviewAndRelatedReviewsFromAPITest 
{
	/*
	 * This is the test that's similar to the search for the data of a user and his/her friends on
	 * facebook, but the API doesn't have a structure for searching book reviews by ID. The
	 * things that will satisfy as the ID of a review will be the Book Title and the reviewer.
	 * 
	 * I will get a specific review(R1) and find other reviews from the same author of the book related to the specific review(R1)
	 */
	public static void main(String args[])
	{
		PrintTextInJFrame printTextInFrame = new PrintTextInJFrame("GetReviewAndRelatedReviewsFromAPITest");
		
		GetReviewDataFromApi getReview = new GetReviewDataFromApi();
		
		LinkedList<String> argumentsNames = new LinkedList<String>();
		argumentsNames.add("user");
		argumentsNames.add("title");
		LinkedList<String> argumentsValues = new LinkedList<String>();
		argumentsValues.add("JustPeachy");
		argumentsValues.add("Breaking Dawn (The Twilight Saga)");
		
		LinkedList<Review> reviews = getReview.getBookReviewsFromRevishAPI(argumentsNames, argumentsValues);
		Review specificReview = reviews.get(0);
		printTextInFrame.write("////////////////// SPECIFIC REVIEW /////////////////");
		printTextInFrame.write("////////////////// SEARCH REVIEW WITH BOOK TITLE= Breaking Dawn (The Twilight Saga) & REVIEWER=JustPeachy /////////////////");
		printTextInFrame.write("ID: " + specificReview.getReviewId());
		printTextInFrame.write("ISBN: " + specificReview.getIsbn());
		printTextInFrame.write("Book title: " + specificReview.getBookTitle());
		LinkedList<String> authors = specificReview.getAuthors();
		printTextInFrame.write("///AUTHORS///");
		for(int j = 0; j < authors.size(); j++)
		{
			 printTextInFrame.write("author: " + authors.get(j));
		}
		printTextInFrame.write("Reviewer: " + specificReview.getReviewer());
		printTextInFrame.write("Review title: " + specificReview.getReviewTitle());
		printTextInFrame.write("Publisher: " + specificReview.getPublisher());
		printTextInFrame.write("Review date: " + specificReview.getReviewDate());
		printTextInFrame.write("Rating: " + specificReview.getRating());
		printTextInFrame.write("URL from review: " + specificReview.getUrlReview());
		printTextInFrame.write("Small cover: " + specificReview.getSmallCover());
		printTextInFrame.write("Medium cover: " + specificReview.getMediumCover());
		printTextInFrame.write("//////Links to shops where you can buy the book///////");
		LinkedList<String> links = specificReview.getLinksWhereToBuyBook();
		for(int k = 0; k < links.size(); k++)
		{
			printTextInFrame.write("link: " + links.get(k));
		}
			
		printTextInFrame.write("Review text: " + specificReview.getReviewText());
			
		printTextInFrame.write("////////////////// END OF SPECIFIC REVIEW /////////////////");
		printTextInFrame.write("////////////////// NOW WE'LL LOOK FOR REVIEWS OF BOOKS FROM THE SAME AUTHOR OF BREAKING DAWN /////////////////");
		
		//Now we'll get the reviews from the same book author
		LinkedList<String> argumentsNamesRelatedBooks = new LinkedList<String>();
		argumentsNamesRelatedBooks.add("author");
		LinkedList<String> argumentsValuesRelatedBooks = new LinkedList<String>();
		argumentsValuesRelatedBooks.add(specificReview.getAuthors().getFirst());//just get the first author
		
		LinkedList<Review> reviewsRelated = getReview.getBookReviewsFromRevishAPI(argumentsNamesRelatedBooks, argumentsValuesRelatedBooks);
		
		for(int i = 0; i < reviewsRelated.size(); i++)
		{
			Review review = reviewsRelated.get(i);
			printTextInFrame.write("////////////////// NEW REVIEW FROM THE SAME AUTHOR /////////////////");
			printTextInFrame.write("ID: " + review.getReviewId());
			printTextInFrame.write("ISBN: " + review.getIsbn());
			printTextInFrame.write("Book title: " + review.getBookTitle());
			authors = review.getAuthors();
			printTextInFrame.write("///AUTHORS///");
			for(int j = 0; j < authors.size(); j++)
			{
				 printTextInFrame.write("author: " + authors.get(j));
			}
			printTextInFrame.write("Reviewer: " + review.getReviewer());
			printTextInFrame.write("Review title: " + review.getReviewTitle());
			printTextInFrame.write("Publisher: " + review.getPublisher());
			printTextInFrame.write("Review date: " + review.getReviewDate());
			printTextInFrame.write("Rating: " + review.getRating());
			printTextInFrame.write("URL from review: " + review.getUrlReview());
			printTextInFrame.write("Small cover: " + review.getSmallCover());
			printTextInFrame.write("Medium cover: " + review.getMediumCover());
			printTextInFrame.write("//////Links to shops where you can buy the book///////");
			links = review.getLinksWhereToBuyBook();
			for(int k = 0; k < links.size(); k++)
			{
				printTextInFrame.write("link: " + links.get(k));
			}
			
			String reviewText = review.getReviewText();
			
			printTextInFrame.write("Review text: " + reviewText);
			
			printTextInFrame.write("////////////////// END OF NEW REVIEW FROM THE SAME AUTHOR /////////////////");
		}
	}
	

}
